package com.funcourse.demo.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

@Document
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AttenderStatics {

  @Id
  String id;

  @Indexed
  String userId;

  Integer rightCount = 0;

  Integer wrongCount = 0;

  Integer competeCount = 0;

  Integer championCount = 0;

  public void increaseRightCount(){
    rightCount = safeIncrease(rightCount);
  }

  public void increaseWrongCount(){
    wrongCount = safeIncrease(wrongCount);
  }

  public void increaseCompeteCount(){
    competeCount = safeIncrease(competeCount);
  }

  public void increaseChampionCount(){
    championCount = safeIncrease(championCount);
  }

  private Integer safeIncrease(Integer i){
    if(null == i){
      i=1;
      return 1;
    }
    return ++i;
  }

}
